// 设备数据收集Api
import request from '@/utils/request'
import { AxiosPromise } from 'axios'

export interface IPageRequest {
  pageNum?: number
  pageSize?: number
}

export interface IDeviceCollectionDataQuery extends IPageRequest {
  tenantId?: number
  channelIndex?: number
  startTime?: number
  endTime?: number
}

export interface IDeviceCollectionDataVo {
  id: number
  tenantId?: number
  collectTime: number
  collectDatetime?: string
  channelIndex?: number
  
  // 波长数据 (Node0-Node29)
  waveLength0?: number
  waveLength1?: number
  waveLength2?: number
  waveLength3?: number
  waveLength4?: number
  waveLength5?: number
  waveLength6?: number
  waveLength7?: number
  waveLength8?: number
  waveLength9?: number
  waveLength10?: number
  waveLength11?: number
  waveLength12?: number
  waveLength13?: number
  waveLength14?: number
  waveLength15?: number
  waveLength16?: number
  waveLength17?: number
  waveLength18?: number
  waveLength19?: number
  waveLength20?: number
  waveLength21?: number
  waveLength22?: number
  waveLength23?: number
  waveLength24?: number
  waveLength25?: number
  waveLength26?: number
  waveLength27?: number
  waveLength28?: number
  waveLength29?: number
  
  // 温度数据 (Node0-Node29)
  tempValue0?: number
  tempValue1?: number
  tempValue2?: number
  tempValue3?: number
  tempValue4?: number
  tempValue5?: number
  tempValue6?: number
  tempValue7?: number
  tempValue8?: number
  tempValue9?: number
  tempValue10?: number
  tempValue11?: number
  tempValue12?: number
  tempValue13?: number
  tempValue14?: number
  tempValue15?: number
  tempValue16?: number
  tempValue17?: number
  tempValue18?: number
  tempValue19?: number
  tempValue20?: number
  tempValue21?: number
  tempValue22?: number
  tempValue23?: number
  tempValue24?: number
  tempValue25?: number
  tempValue26?: number
  tempValue27?: number
  tempValue28?: number
  tempValue29?: number
}

enum Api {
  deviceCollectionList = '/deviceCollectionData/page',
  deviceCollectionTimeRange = '/deviceCollectionData/time-range',
  deviceCollectionTimeRangePage = '/deviceCollectionData/time-range/page',
  deviceCollectionCount = '/deviceCollectionData/count',
  deviceCollectionExport = '/deviceCollectionData/export',
}

// 获取设备数据收集列表
export const getDeviceCollectionList = (data: IDeviceCollectionDataQuery): AxiosPromise<any> => {
  return request({
    url: Api.deviceCollectionList,
    method: 'post',
    data,
  })
}

// 获取所有数据
export const getAllDeviceCollection = (): AxiosPromise<any> => {
  return request({
    url: Api.deviceCollectionList.replace('/page', ''),
    method: 'get',
  })
}

// 根据时间范围获取列表
export const getDeviceCollectionByTimeRange = (startTime: number, endTime: number): AxiosPromise<any> => {
  return request({
    url: Api.deviceCollectionTimeRange + `?startTime=${startTime}&endTime=${endTime}`,
    method: 'get',
  })
}

// 根据时间范围分页获取
export const getDeviceCollectionPageByTimeRange = (startTime: number, endTime: number, data: IDeviceCollectionDataQuery): AxiosPromise<any> => {
  return request({
    url: Api.deviceCollectionTimeRangePage + `?startTime=${startTime}&endTime=${endTime}`,
    method: 'post',
    data,
  })
}

// 获取数据总数
export const getDeviceCollectionCount = (): AxiosPromise<any> => {
  return request({
    url: Api.deviceCollectionCount,
    method: 'get',
  })
}

// 导出设备数据收集记录
export const exportDeviceCollection = (data: IDeviceCollectionDataQuery): AxiosPromise<any> => {
  return request({
    url: Api.deviceCollectionExport,
    method: 'post',
    data,
    responseType: 'blob',
  })
}